home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
TBINDER.HPP
< prev
Wrap
C/C++ Source or Header
|
1992-05-12
|
8KB
|
356 lines
/*
TBinder.hpp -- Loose Data Binder v 1.7:
container class template.
(C) Copyright 1992 John W. Small
All rights reserved
PSW / Power SoftWare
P.O. Box 10072
McLean, Virginia 22102 8072 USA
(703) 759-3838
*/
#ifndef TBinder_HPP
#define TBinder_HPP
#ifndef BINDER_HPP
#include "binder.hpp"
#endif
/*
To use the TBinder template, TYPE must have:
default constructor
copy initializer constructor,
i.e. TYPE(TYPE&)
destructor
assignment operator, i.e. operator=()
ostream& operator<<(ostream&,TYPE&)
istream& operator>>(istream&,TYPE&)
*/
template <class TYPE>
class TBinder : Binder {
protected:
TBinder (initVFTs)
: Binder(initVFTsOnly) {}
Binder:: destruct;
virtual voiD Dassign(voiD D, const voiD S)
{ (*(TYPE *)D) = (*(TYPE *)S);
return D; }
virtual voiD Dnew(const voiD D)
{ return (voiD)
new TYPE(*(TYPE *)D); }
virtual void Ddelete(voiD D)
{ delete (TYPE *) D; }
Binder:: Dattach;
Binder:: Ddetach;
Binder:: sberror;
Binder:: berror;
virtual void Dstore(ostream& os, voiD D)
{ os << *(TYPE *)D << BDRendm; }
virtual voiD Dload(istream& is)
{ TYPE t; is >> t >> BDRnextm;
return (voiD) new TYPE(t); }
Binder:: store;
static TBinder<TYPE> * load(istream& is,
TBinder<TYPE> * thiS);
Binder:: vload;
friend ostream& operator<<(ostream&,
TBinder<TYPE>&);
friend istream& operator>>(istream&,
TBinder<TYPE>*&);
public:
/* Constructors and destructor */
TBinder (unsigned flags = BDR_BIND_ONLY,
unsigned maxNodes = BDR_MAXNODES,
unsigned limit = BDR_LIMIT,
unsigned delta = BDR_DELTA) :
Binder(flags,maxNodes,limit,delta)
{}
TBinder (TYPE * argv[],
unsigned argc = 0,
unsigned flags = BDR_BIND_ONLY)
: Binder((voiDV)argv,argc,flags) {}
TBinder (const char *filename)
: Binder(initVFTsOnly)
{ (void) vload(filename,(BDRsloaD)
TBinder<TYPE>::load,this); }
Binder::save;
TYPE ** vector()
{ return (TYPE **)Binder::
vector(); }
virtual ~TBinder() { TBinder<TYPE>::destruct(); }
/* Housekeeping Primitives */
Binder:: Limit;
Binder:: setLimit;
Binder:: pack;
Binder:: Delta;
Binder:: setDelta;
Binder:: Nodes;
Binder:: MaxNodes;
Binder:: setMaxNodes;
Binder:: vacancy;
Binder:: vacancyNonElastic;
Binder:: Flags;
Binder:: setFlags;
Binder:: resetFlags;
TBinder<TYPE>& operator<<(TBinder<TYPE>&
(*manipulator)(TBinder<TYPE>&))
{ return (manipulator?
(*manipulator)
(*this) : *this); }
/* Elastic Array Primitives */
TYPE * atIns(unsigned n, TYPE * D)
{ return (TYPE *)Binder::
atIns(n,(voiD)D); }
TYPE * atInsNew(unsigned n, const TYPE * D)
{ return (TYPE *)Binder::
atInsNew(n,(const voiD)D); }
TYPE * atRmv(unsigned n)
{ return (TYPE *)Binder::
atRmv(n); }
Binder:: allRmv;
Binder:: atDel;
TYPE * atDelAsg(unsigned n, TYPE * D)
{ return (TYPE *)Binder::
atDelAsg(n,(voiD)D); }
Binder:: allDel;
TYPE * atPut(unsigned n, TYPE * D)
{ return (TYPE *)Binder::
atPut(n,(voiD)D); }
TYPE * atPutNew(unsigned n, const TYPE * D)
{ return (TYPE *)Binder::
atPutNew(n,(const voiD)D); }
TYPE * atPutAsg(unsigned n, const TYPE * D)
{ return (TYPE *)Binder::
atPutAsg(n,(const voiD)D); }
TYPE * atGet(unsigned n)
{ return (TYPE *)Binder::
atGet(n); }
TYPE * operator[](unsigned n)
{ return atGet(n); }
TYPE * atGetAsg(unsigned n, TYPE * D)
{ return (TYPE *)Binder::
atGetAsg(n,(voiD) D); }
TYPE * atXchg(unsigned n, TYPE * D)
{ return (TYPE *)Binder::
atXchg(n,(voiD) D); }
unsigned index(const TYPE * D)
{ return Binder::
index((const voiD)D); }
Binder:: forEach;
/* Stack - Deque - Queue Primitives */
TYPE * push(TYPE * D)
{ return (TYPE *)Binder::
push((voiD) D); }
TYPE * pushNew(const TYPE * D)
{ return (TYPE *)Binder::
pushNew((const voiD)D); }
TYPE * pop()
{ return (TYPE *)Binder::
pop(); }
TBinder<TYPE>& operator>>(TYPE *& D)
{ D = atRmv(0); return *this; }
Binder:: popDel;
TYPE * popDelAsg(TYPE * D)
{ return (TYPE *)Binder::
popDelAsg((voiD)D); }
TYPE * top()
{ return (TYPE *)Binder::
top(); }
TYPE * topAsg(TYPE * D)
{ return (TYPE *)Binder::
topAsg((voiD)D); }
TYPE * insQ(TYPE * D)
{ return (TYPE *)Binder::
insQ((voiD)D); }
TBinder<TYPE>& operator<<(TYPE * D)
{ atIns(Nodes(),D); return *this; }
TYPE * insQNew(const TYPE * D)
{ return (TYPE *)Binder::
insQNew((const voiD)D); }
TYPE * unQ()
{ return (TYPE *)Binder::
unQ(); }
Binder:: unQDel;
TYPE * unQDelAsg(TYPE * D)
{ return (TYPE *)Binder::
unQDelAsg((voiD)D); }
TYPE * rear()
{ return (TYPE *)Binder::
rear(); }
TYPE * rearAsg(TYPE * D)
{ return (TYPE *)Binder::
rearAsg((voiD)D); }
/* List (single and double linked) Primitives */
Binder:: CurNode;
Binder:: setCurNode;
TYPE * ins(TYPE * D)
{ return (TYPE *)Binder::
ins((voiD)D); }
TYPE * insNew(const TYPE * D)
{ return (TYPE *)Binder::
insNew((const voiD)D); }
TYPE * rmv()
{ return (TYPE *)Binder::
rmv(); }
Binder:: del;
TYPE * delAsg(TYPE * D)
{ return (TYPE *)Binder::
delAsg((voiD)D); }
TYPE * put(TYPE * D)
{ return (TYPE *)Binder::
put((voiD)D); }
TYPE * putNew(const TYPE * D)
{ return (TYPE *)Binder::
putNew((const voiD)D); }
TYPE * putAsg(const TYPE * D)
{ return (TYPE *)Binder::
putAsg((const voiD)D); }
TYPE * get()
{ return (TYPE *)Binder::
get(); }
operator TYPE *() { return get(); }
TYPE * getAsg(TYPE * D)
{ return (TYPE *)Binder::
getAsg((voiD)D); }
TYPE * next()
{ return (TYPE *)Binder::
next(); }
TYPE * operator++()
{ return next(); }
TYPE * nextAsg(TYPE * D)
{ return (TYPE *)Binder::
nextAsg((voiD)D); }
TYPE * prev()
{ return (TYPE *)Binder::
prev(); }
TYPE * operator--()
{ return prev(); }
TYPE * prevAsg(TYPE * D)
{ return (TYPE *)Binder::
prevAsg((voiD)D); }
TYPE * firstThat(BDRdetecT B, voiD M = voiD0)
{ return (TYPE *)Binder::
firstThat(B,M); }
TYPE * lastThat(BDRdetecT B, voiD M = voiD0)
{ return (TYPE *)Binder::
lastThat(B,M); }
/* Priority Q, Set, Bag, Dictionary, Sort Primitives */
Binder:: Sorted;
Binder:: unSort;
Binder:: setComP;
Binder:: ComP;
Binder:: sort;
TYPE * insSort(TYPE * D)
{ return (TYPE *)Binder::
insSort((voiD)D); }
TYPE * insSortNew(const TYPE * D)
{ return (TYPE *)Binder::
insSortNew((const voiD)D); }
TYPE * insUnique(TYPE * D)
{ return (TYPE *)Binder::
insUnique((voiD)D); }
TYPE * insUniqueNew(const TYPE * D)
{ return (TYPE *)Binder::
insUniqueNew((const voiD)D); }
TYPE * findFirst(const TYPE * K)
{ return (TYPE *)Binder::
findFirst((const voiD)K); }
TYPE * findNext(const TYPE * K)
{ return (TYPE *)Binder::
findNext((const voiD)K); }
TYPE * findLast (const TYPE * K)
{ return (TYPE *)Binder::
findLast((const voiD)K); }
TYPE * findPrev(const TYPE * K)
{ return (TYPE *)Binder::
findPrev((const voiD)K); }
unsigned findAll(const TYPE * K)
{ return Binder::
findAll((const voiD)K); }
}; /* class TBinder */
template <class TYPE>
TBinder<TYPE>* TBinder<TYPE>::load(istream& is,
TBinder<TYPE>* thiS)
{
int newed;
if (thiS)
newed = 0;
else {
if ((thiS = new TBinder<TYPE>
(initVFTsOnly))
== voiD0) {
sberror("unable to construct "
"new TBinder for "
"loading");
return (TBinder<TYPE> *)0;
}
newed = 1;
}
if (!Binder::load(is,(BindeR)thiS)) {
if (newed)
delete (voiD) thiS;
return (TBinder<TYPE> *)0;
}
return thiS;
}
#define TBINDER(TYPE,TYPEBINDER,TYPEBINDERPTR) \
inline ostream& operator<<(ostream& os, \
TBinder<TYPE>& b) \
{ \
if (b.Flags(BDR_DSTORE)) \
b.store(os); \
return os; \
} \
inline istream& operator>>(istream& is, \
TBinder<TYPE>*& B) \
{ B = TBinder<TYPE>:: \
load(is,(TBinder<TYPE> *)0); \
return is; } \
typedef TBinder<TYPE> TYPEBINDER; \
typedef TYPEBINDER * TYPEBINDERPTR
#endif /* TBinder_HPP */